package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.Device;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface DeviceMapper {
    @Delete({
        "delete from device",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into device (id, terminal_type, ",
        "os_version, brand, ",
        "model, device_id, ",
        "register_ip, register_time, ",
        "register_uid, login_uid)",
        "values (#{id,jdbcType=BIGINT}, #{terminalType,jdbcType=TINYINT}, ",
        "#{osVersion,jdbcType=VARCHAR}, #{brand,jdbcType=VARCHAR}, ",
        "#{model,jdbcType=VARCHAR}, #{deviceId,jdbcType=VARCHAR}, ",
        "#{registerIp,jdbcType=VARCHAR}, #{registerTime,jdbcType=TIMESTAMP}, ",
        "#{registerUid,jdbcType=BIGINT}, #{loginUid,jdbcType=BIGINT})"
    })
    int insert(Device record);

    int insertSelective(Device record);

    @Select({
        "select",
        "id, terminal_type, os_version, brand, model, device_id, register_ip, register_time, ",
        "register_uid, login_uid",
        "from device",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    Device selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Device record);

    @Update({
        "update device",
        "set terminal_type = #{terminalType,jdbcType=TINYINT},",
          "os_version = #{osVersion,jdbcType=VARCHAR},",
          "brand = #{brand,jdbcType=VARCHAR},",
          "model = #{model,jdbcType=VARCHAR},",
          "device_id = #{deviceId,jdbcType=VARCHAR},",
          "register_ip = #{registerIp,jdbcType=VARCHAR},",
          "register_time = #{registerTime,jdbcType=TIMESTAMP},",
          "register_uid = #{registerUid,jdbcType=BIGINT},",
          "login_uid = #{loginUid,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Device record);


    /***********以下为自定义方法************************/

    @Select({
            "select * ",
            "from device",
            "where device_id = #{deviceId,jdbcType=VARCHAR}"
    })
    @ResultMap("BaseResultMap")
    Device selectByDeviceId(String deviceId);
}